const mysql = require('mysql');
const config = require('./mysql_config.js');
const conn = mysql.createConnection(config);

conn.connect(e => {
  if(e) {
    throw e;
  }
  console.log('mysql connected...');
})

const query = (sql, params) => {
  return new Promise((resolve, reject) => {
    conn.query(sql, params, (e, res) => {
      if(e) {
        reject(e);
      }else {
        resolve(res);
      }
    })
  })
}

module.exports = {conn, query};